//Copyright  2015 Max "Shrinker" Wieden
//Refer to license for license details.

//this grammar matches Half-Life 1 MAP files
//trained with a quick test with Hammer 3.4
Tokens:
	FloatLiteral         = [['+', '-']] (BaseFloatLiteral [FloatExponent] | NumericLiteral FloatExponent);
	#FloatExponent       = ['E', 'e'] [['+', '-']] (Digit)+;
	IntLiteral           = [['+', '-']] NumericLiteral;
	TextureName          = FirstNameChar (FirstNameChar | Digit)+ | SimpleFirstNameChar;
	LBrace               = '{';
	LBracket             = '[';
	LPar                 = '(';
	RBrace               = '}';
	RBracket             = ']';
	RPar                 = ')';
	StringLiteral        = '\"' (~['\"'])* '\"';
	#FirstNameChar       = SimpleFirstNameChar | ['+', '-', '{'];
	#Digit               = ['0'-'9'];
	#SimpleFirstNameChar = ['A'-'Z'] | ['a'-'z'] | ['!', '#', '_', '~'];
	#NumericLiteral      = '0' | ['1'-'9'] (Digit)*;
	#BaseFloatLiteral    = (Digit)+ '.' (Digit)* | '.' (Digit)+;

FillerTokens:
	Whitespace = (['\t', ' ', '\r', '\n'])+;

TokenSpecializations:

Rules:
Start = {
	(Entity)*
	EOF
}

Entity = {
	LBrace
	(KeyValuePair)+
	(Solid       )*
	RBrace
}

Solid = {
	LBrace
	(Side)*
	RBrace
}

Side = {
	LPar (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) RPar
	LPar (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) RPar
	LPar (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) RPar
	TextureName
	LBracket (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) RBracket
	LBracket (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) RBracket
	(IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral)
}

KeyValuePair = {StringLiteral StringLiteral}
